package com.jdk.demo.nio.bytebuffer;

import java.nio.ByteBuffer;

public class 缓冲区扩容 {
	
	public static void main(String[] args) {
		byte[] byteArrayIn1 = {1, 2, 3, 4, 5};
		ByteBuffer bytebuffer1 = ByteBuffer.wrap(byteArrayIn1);
		ByteBuffer bytebuffer2 = extendsSize(bytebuffer1, 2);
		byte[] newArray = bytebuffer2.array();
		for (int i = 0; i < newArray.length; i++) {
			System.out.print(newArray[i] + " ");
		}
		System.out.println();
	}

	private static ByteBuffer extendsSize(ByteBuffer buffer, int extendsSize) {
		ByteBuffer newByteBuffer = ByteBuffer.allocate(buffer.capacity() + extendsSize);
		newByteBuffer.put(buffer);
		return newByteBuffer;
	}

}
